package com.company.堆栈队列;

import java.util.Scanner;
import java.util.Stack;

/**
 * @author zhangjian
 * @data 2023/4/1
 * @Version 1.0
 * @Descripion AB1 【模板】栈
 */
public class AB1模板栈 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        Stack<String> stack = new Stack<>();
        int n = input.nextInt();
        input.nextLine();
        for (int i = 0; i < n; i++) {
            String[] str = input.nextLine().split(" ");
            switch (str[0]) {
                case "push":
                    stack.push(str[1]);
                    break;
                case "pop":
                    if (stack.isEmpty()) {
                        System.out.println("error");
                    } else {
                        System.out.println(stack.pop());
                    }
                    break;
                default:
                    if (stack.isEmpty()) {
                        System.out.println("error");
                    } else {
                        System.out.println(stack.peek());
                    }
                    break;
            }
        }
    }
}
